package com.demo.apparel.service.web.Impl;

import com.demo.apparel.entity.AdminLogoutLog;
import com.demo.apparel.mapper.web.AdminLogoutLogMapper;
import com.demo.apparel.service.web.LogoutService;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;

@Service
@RequiredArgsConstructor
public class LogoutServiceImpl implements LogoutService {

    private final AdminLogoutLogMapper adminLogoutLogMapper;

    @Override
    public void logout(HttpServletRequest request) {
        AdminLogoutLog log = new AdminLogoutLog();
        log.setUserId((String) request.getAttribute("userId"));
        log.setLogoutTime(LocalDateTime.now());
//        log.setIpAddress(request.getRemoteAddr());
//        log.setUserAgent(request.getHeader("User-Agent"));

        adminLogoutLogMapper.insertLogoutLog(log);
    }
}
